home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
win
/
general
/
cdbw.exe
/
SCLIENT.C
< prev
next >
Wrap
Text File
|
1991-08-28
|
20KB
|
669 lines
/*
* SCLIENT.C
*
* This module contains functions associated with the client dialog box
* in SAMPLE.EXE.
*
* Copyright (C) 1991 by Daytris. All rights reserved.
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#ifndef ZORTECH
#include <memory.h>
#endif
#include "dbmgr.h"
#include "sampledb.h"
#include "sample.h"
/************************************************
* Local data
************************************************/
static CLIENT client;
static enum
{
MODE_ADD,
MODE_UPDATE,
MODE_DELETE
} eMode;
static BOOL bAddressChange;
static HANDLE hAddresses;
/************************************************
* Function Declarations
************************************************/
BOOL AddClientDlg( HWND hWnd);
BOOL UpdateClientDlg( HWND hWnd);
BOOL DeleteClientDlg( HWND hWnd);
static BOOL GetSelectedClient( HWND hWnd, CLIENT *pClient, short *pIndexSel);
static BOOL AddClientAddresses( HWND hWnd);
static BOOL DeleteClientAddresses( HWND hWnd);
static BOOL FreeClientAddresses( HWND hWnd);
BOOL FAR PASCAL ClientProc( HWND hDlg, unsigned iMessage, WORD wParam,
LONG lParam);
static void SetClientFields( HWND hDlg);
static BOOL GetClientFields( HWND hDlg);
static BOOL StoreAddressHandles( HWND hDlg);
/***************************************************************************
* Function : AddClientDlg
*
* Purpose : This function drives the add client dialog box.
*
* Returns : TRUE - client added
* FALSE - add aborted or error in add
***************************************************************************/
BOOL AddClientDlg( HANDLE hWnd)
{
short nStatus;
DWORD dwStatus;
FARPROC lpfnClientProc;
/* Set static variables */
eMode = MODE_ADD;
bAddressChange = FALSE;
/* Initialize the client structure */
memset( &client, 0, sizeof( CLIENT));
client.lClientNbr = setup.lNextClientNbr;
/* Create an instance and open the Client window */
lpfnClientProc = MakeProcInstance( ClientProc, hInst);
nStatus = DialogBox( hInst, "client", hWnd, lpfnClientProc);
FreeProcInstance( lpfnClientProc);
/* User selected OK */
if( nStatus == IDOK)
{
/* Add the client */
if( dwStatus = XDbRecordAdd( hDb, "client", &client,
sizeof( CLIENT)) )
{
DbError( hWnd, dwStatus, __FILE__, __LINE__);
return FALSE;
}
/* Add the member addresses */
if( bAddressChange)
{
if( ! AddClientAddresses( hWnd))
return FALSE;
}
/* Increment the client number counter and update the setup
record */
setup.lNextClientNbr++;
if( dwStatus = XDbRecordUpdate( hDb, "setup", &setup,
sizeof( SETUP)))
{
DbError( hWnd, dwStatus, __FILE__, __LINE__);
return FALSE;
}
/* Flush the database */
DbFlush( hDb);
/* Add the client to the list box */
AddToClientListBox( hWnd, &client);
}
else /* IDCANCEL */
{
/* Free all address handles for this client */
if( ! FreeClientAddresses( hWnd))
return FALSE;
}
return TRUE;
}
/***************************************************************************
* Function : UpdateClientDlg
*
* Purpose : This function drives the add client dialog box.
*
* Returns : TRUE - client added
* FALSE - update aborted or error in update
***************************************************************************/
BOOL UpdateClientDlg( HANDLE hWnd)
{
short nStatus, nIndex;
DWORD dwStatus;
FARPROC lpfnClientProc;
/* Set the mode */
eMode = MODE_UPDATE;
/* Initialize the client structure */
if( ! GetSelectedClient( hWnd, &client, &nIndex))
{
MessageBeep( 0);
return FALSE;
}
/* Create an instance and open the Client window */
lpfnClientProc = MakeProcInstance( ClientProc, hInst);
nStatus = DialogBox( hInst, "client", hWnd, lpfnClientProc);
FreeProcInstance( lpfnClientProc);
/* User selected OK */
if( nStatus == IDOK)
{
/* Update the client */
if( dwStatus = XDbRecordUpdate( hDb, "client", &client,
sizeof( CLIENT)) )
{
DbError( hWnd, dwStatus, __FILE__, __LINE__);
return FALSE;
}
/* If any address has changed, delete all member addresses and
add addresses in handle table. */
if( bAddressChange)
{
if( ! DeleteClientAddresses( hWnd))
return FALSE;
if( ! AddClientAddresses( hWnd))
return FALSE;
}
/* Flush the database */
DbFlush( hDb);
/* Update the listbox */
DeleteFromClientListBox( hWnd, nIndex);
AddToClientListBox( hWnd, &client);
}
else /* IDCANCEL */
{
/* Free all address handles for this client */
if( ! FreeClientAddresses( hWnd))
return FALSE;
}
return TRUE;
}
/***************************************************************************
* Function : DeleteClientDlg
*
* Purpose : This function drives the client record deletion process.
*
* Returns : TRUE - client deleted
* FALSE - delete aborted or error in delete
***************************************************************************/
BOOL DeleteClientDlg( HWND hWnd)
{
short nStatus, nIndex;
DWORD dwStatus;
/* Initialize the client structure */
if( ! GetSelectedClient( hWnd, &client, &nIndex))
{
MessageBeep( 0);
return FALSE;
}
/* Ask user if they're sure */
nStatus = MessageBox( hWnd, "Are you sure?", "Delete Client",
MB_ICONQUESTION | MB_YESNO);
/* User selected YES */
if( nStatus == IDYES)
{
/* Delete all member addresses */
if( ! DeleteClientAddresses( hWnd))
return FALSE;
/* Delete the client */
if( dwStatus = DbRecordDelete( hDb, "client"))
{
DbError( hWnd, dwStatus, __FILE__, __LINE__);
return FALSE;
}
/* Flush the database */
DbFlush( hDb);
/* Remove client from listbox */
if( ! DeleteFromClientListBox( hWnd, nIndex))
return FALSE;
}
return TRUE;
}
/***************************************************************************
* Function : GetSelectedClient
*
* Purpose : This function retrieves the selected client record from
* the database. It uses the client number in the string
* of the listbox as a key value to retrieve upon. The
* listbox index is also returned.
*
* Returns : TRUE - client retrieved
* FALSE - error
***************************************************************************/
static BOOL GetSelectedClient( HWND hWnd, CLIENT *pClient, short *pIndex)
{
LONG lKey;
DWORD dwStatus;
char szBuffer[64], *pTemp;
/* Get the listbox selection */
if( (*pIndex = (short)SendMessage( hWndClientLB, LB_GETCURSEL, 0, 0L))
== LB_ERR)
{
return FALSE;
}
if( SendMessage( hWndClientLB, LB_GETTEXT, *pIndex,
(LONG)(LPSTR)szBuffer) == LB_ERR)
{
MessageBox( hWnd, "SendMessage / LB_GETTEXT", "Fatal Error",
MB_ICONEXCLAMATION | MB_OK);
return FALSE;
}
/* Find the client number in the selected string */
if( bSortByNumber)
pTemp = strtok( szBuffer, " ");
else
{
pTemp = strchr( szBuffer, 0);
for( pTemp-- ; *pTemp != ' ' ; pTemp--)
;
pTem